
package com.wyzz.hr.action;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.base.DWRUtil;
import com.wyzz.hr.util.InterpreterForPerformance;
import com.wyzz.hr.util.StringUtil;

public class DwrforCritFormulaValidate extends BaseAction {

	public DwrforCritFormulaValidate() {
		msgFormulaIllegal = "\u60A8\u8F93\u5165\u7684\u516C\u5F0F{0}\u4E0D\u5408\u6CD5\uFF1A{1}";
		msgFormulaLegal = "{0}:\u60A8\u8F93\u5165\u7684\u516C\u5F0F{1}\u5408\u6CD5\u3002";
		msgNoAuth = "{0}:\u60A8\u65E0\u6743\u6267\u884C\u6B64\u64CD\u4F5C\uFF0C\u8BF7\u91CD\u65B0\u767B\u9646\uFF01";
	}

	public String validateFormula(String formula) {
		System.out.println(formula);
		if ("error".equalsIgnoreCase(DWRUtil.checkAuth("addPerfschema",
				"execute")))
			return StringUtil.message(msgNoAuth, new Object[] { "noauth" });
		InterpreterForPerformance interpreter = new InterpreterForPerformance();
		System.out.println(formula);
		String info = interpreter.formulaValidate(formula);
		System.out.println(info);
		if (!"SUCC".equals(info))
			return StringUtil.message(msgFormulaIllegal, new Object[] {
					formula, info });
		else
			return StringUtil.message(msgFormulaLegal, new Object[] { "SUCC",
					formula });
	}

	private static final long serialVersionUID = 1L;
	private String msgFormulaIllegal;
	private String msgFormulaLegal;
	private String msgNoAuth;
}
